package q442_findDuplicates;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution_1 {
    /*
    该方法不满足空间复杂度为常数
     */
    public List<Integer> findDuplicates(int[] nums) {
        List<Integer> res = new ArrayList<>();
        if (nums.length == 1) {
            return res;
        }
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if (set.contains(nums[i])) {
                res.add(nums[i]);
            }
            set.add(nums[i]);
        }
        return res;
    }
}
